/*
 * @Author: your name
 * @Date: 2019-12-02 10:17:01
 * @LastEditTime : 2019-12-26 16:45:44
 * @LastEditors  : Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \pc\src\pages\OperatingPlan\ContractPlan\Approve\models\items.js
 */
import _ from 'lodash';
import * as api from '@/services/ContractPlanMgr';
import * as uploadApi from '@/services/upload';

const Model = {
  namespace: 'SigningApprove',
  state: {
    item: [],
  },
  effects: {
    // 基本信息-本次编排版本-全盘年度指标-全盘月度指标-月均销售同比偏差
    *init({ payload, callback }, { call, put }) {
      const response = yield call(api.getApprovalPreviewUsingGET, payload);
      if (response && response.data && !_.isEmpty(response.data)) {
        const { data } = response;
        yield put({
          type: 'save',
          payload: {
            item: data,
          },
        });
      }
      if (callback) callback(response.data);
    },
    // 删除上传的文件
    *deleteFile({ payload, callback }, { call, put }) {
      const response = yield call(uploadApi.createFileDeleteUsingDelete, payload);
      if (callback) callback(response && response.data ? response.data : []);
    },
    // 提交到OA审批
    *approved({ payload, callback }, { call, put }) {
      const response = yield call(api.submitToOAUsingPOST_1, payload);
      if (callback) callback(response);
    },
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
};
export default Model;
